<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>专家回复界面</title>
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <script src="../../res/js/Tools.js"></script>
    <script src="../../res/layui/layui.js"></script>
</head>
<body>
    <form id="atsfrom">
        <div class="layui-form-item" style="margin-top: 10px">
            <label class="layui-form-label">方案名称</label>
            <div class="layui-input-inline">
                <input type="hidden" name="schemeId" id="schemeId">
                <input type="text" id="schemeName" name="saName" class="layui-input layui-disabled" readonly>
            </div>
        </div>
        <div class="layui-form-item" style="margin-top: 10px">
            <label class="layui-form-label">附件</label>
            <div class="layui-input-inline">
                <button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件</button>
                <input type="text" disabled readonly="readonly" id="upfile" style="width:300px;background: #ffffff;border:none">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            </div>
        </div>
    </form>
<script>
    var id = getQueryString("id");
    layui.use(['upload','form'], function(){
        var $ = layui.jquery
        ,form = layui.form
        ,upload = layui.upload;
        findAtsScheme();
        //监听提交
        form.on('submit(formDemo)', function(data){
            var formData = new FormData(document.getElementById("atsfrom"));
            var url="../../mase/reply";
            $.ajax({
                url:url,
                type:"post",
                data:formData,
                async:false,
                processData:false,
                contentType:false,
                dataType:"json",
                success:function(obj){
                    if(obj.num==1){
                        layer.msg(obj.msg,{
                            icon:1,
                            time:1000 //1秒关闭(如果不配置默认三秒)
                        },function(){
                            //关闭当前层
                            //当你在iframe页面关闭自身时
                            var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            //刷新父页面
                            parent.location.reload();
                        });
                    }else{
                        alert(obj.msg);
                    }
                }
            });
            return false;
        })
        upload.render({
            elem: '#test3'
            ,auto: false
            ,accept: 'file'
            ,choose: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                obj.preview(function(index, file, result){
                    $("#upfile").val(file.name);
                });
            }
            ,done: function(res){
                console.log(res)
            }
        });
    });
    function findAtsScheme(){
        var id=getQueryString("id");
        var url = "../../mentalityas/findBySchemeId";
        var data = {'id':id};
        $.post(url,data,function(obj){
            $("#schemeName").val(obj.schemeName);
            $("#schemeId").val(obj.schemeId);
            //重新渲染
            form.render();
        },"json");
    }
</script>
</body>
</html>